home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / et / et3_0-a1.lha / et3 / src / CLib.C < prev    next >
C/C++ Source or Header  |  1992-08-26  |  2KB  |  153 lines

  1. #ifdef __GNUG__
  2. #pragma implementation
  3. #endif
  4.  
  5. #include "CLib.h"
  6.  
  7. #include <stdlib.h>
  8. #include <osfcn.h>
  9. #include <unistd.h>
  10.  
  11. extern int gDebug;
  12.  
  13. #ifdef __GNUG__
  14. #   include <errno.h>
  15. #   include <fcntl.h>
  16. #endif
  17.  
  18. int &CLib::ErrNo= ::errno;
  19. char **CLib::Environ= ::environ;
  20.  
  21. void CLib::QSort(
  22.     void *base, int nel, int width, int (*cmp)(const void*, const void*)
  23. )
  24. {
  25.     ::qsort(base, nel, width, cmp);
  26. }
  27.     
  28. char* CLib::BSearch(
  29.     const char *key, char *base, unsigned nel, int size, 
  30.     int (*cmp)(const void*, const void*)
  31. )
  32. {
  33.     return (char*) ::bsearch(key, base, nel, size, cmp); 
  34. }
  35.    
  36. char* CLib::Getenv(const char *name)
  37. {
  38.     return ::getenv(name);
  39. }
  40.     
  41. int CLib::Putenv(const char *entry)
  42. {
  43.     return ::putenv(entry);
  44. }
  45.     
  46. int CLib::System(const char *cmd)
  47. {
  48.     return ::system(cmd);
  49. }
  50.     
  51. void CLib::Abort()
  52. {
  53.     ::abort();
  54. }
  55.     
  56. unsigned int CLib::Alarm(unsigned int secs)
  57. {
  58.     return ::alarm(secs);
  59. }
  60.  
  61. void CLib::Exit(int code)
  62. {
  63.     if (gDebug) {
  64.     fprintf(stderr, "Clib::Exit(%d)\n", code);
  65.     Abort();
  66.     }
  67.     return ::exit(code);
  68. }
  69.  
  70. void CLib::FastExit(int code)
  71. {
  72.     return ::_exit(code);
  73. }
  74.  
  75. int CLib::Open(const char *name, int mode)
  76. {
  77.     return ::open(name, mode);
  78. }
  79.  
  80. int CLib::Creat(const char *name, int mode)
  81. {
  82.     return ::creat(name, mode);
  83. }
  84.  
  85. int CLib::Read(int fd, char *buf, int sz)
  86. {
  87.     int ec= ::read(fd, buf, sz);
  88.     if (ec < 0) {
  89.     if (errno == EWOULDBLOCK || errno == EAGAIN)
  90.         return -2;
  91.     perror("CLib::Read");
  92.     return -1;      // fatal error
  93.     }
  94.     return ec;  // ok or EOF
  95. }
  96.  
  97. int CLib::Write(int fd, const char *buf, unsigned int sz)
  98. {
  99.     int ec= ::write(fd, buf, sz);
  100.     if (ec < 0) {
  101.     if (errno == EWOULDBLOCK || errno == EAGAIN)
  102.         return -2;
  103.     perror("CLib::Write");
  104.     return -1;      // fatal error
  105.     }
  106.     return ec;
  107. }
  108.  
  109. int CLib::Close(int fd)
  110. {
  111.     int ec= ::close(fd);
  112.     if (ec < 0) {
  113.     perror("CLib::Close");
  114.     }
  115.     return ec;
  116. }
  117.  
  118. long CLib::Lseek(int fd, long off, int mode)
  119. {
  120.     return ::lseek(fd, off, mode);
  121. }
  122.  
  123. int CLib::Unlink(const char *name)
  124. {
  125.     return ::unlink(name);    
  126. }
  127.  
  128. int CLib::Link(const char *from, const char *to)
  129. {
  130.     return ::link(from, to);
  131. }
  132.  
  133. int CLib::Free(char *p)
  134. {
  135. #ifdef __GNUG__
  136.     ::free(p);
  137.     return 0;
  138. #else
  139.     return ::free(p);
  140. #endif
  141. }
  142.  
  143. char *CLib::ReAlloc(char *p, int sz)
  144. {
  145.     return ::realloc(p, sz);
  146. }
  147.  
  148. char *CLib::CAlloc(int n, int sz)
  149. {
  150.     return ::calloc(n, sz);
  151. }
  152.  
  153.